<script setup lang="ts">
import { Refresh } from "@element-plus/icons-vue";

// 定义emits
const emit = defineEmits<{
  (e: "refresh"): void;
  (e: "switchToPassword"): void;
}>();

// 刷新二维码
const refreshQrcode = () => {
  ElMessage.success("二维码已刷新");
  emit("refresh");
  // 实际项目中这里应该重新获取二维码
};

// 切换到密码登录
const switchToPasswordLogin = () => {
  emit("switchToPassword");
};
</script>

<template>
  <div class="scan-login">
    <div class="qrcode-container">
      <div class="qrcode">
        <img
          src="https://picsum.photos/200/200"
          alt="登录二维码"
          class="qrcode-img"
        />
        <div class="qrcode-refresh" @click="refreshQrcode">
          <el-icon size="16"><Refresh /></el-icon>
        </div>
      </div>
      <p class="qrcode-desc">请使用企业APP扫码登录</p>
    </div>
    <div class="scan-spacer"></div>
    <div class="scan-footer">
      <el-button link class="scan-switch-btn" @click="switchToPasswordLogin">
        切换至密码登录
      </el-button>
    </div>
  </div>
</template>

<style scoped lang="scss">
@use "../styles/variables.scss" as vars;

.scan-login {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0;
  .qrcode-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    .qrcode {
      position: relative;
      width: 200px;
      height: 200px;
      border: 1px solid #eee;
      border-radius: vars.$radius;
      padding: 10px;
      margin-bottom: 15px;
      .qrcode-img {
        width: 100%;
        height: 100%;
        object-fit: contain;
        border-radius: 4px;
      }
      .qrcode-refresh {
        position: absolute;
        bottom: 5px;
        right: 5px;
        width: 30px;
        height: 30px;
        border-radius: 50%;
        background-color: rgba(255, 255, 255, 0.8);
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        transition: background-color 0.2s;
        &:hover {
          background-color: vars.$white-color;
        }
      }
    }
    .qrcode-desc {
      font-size: 14px;
      color: vars.$light-text-color;
      margin: 0;
    }
  }
  .scan-footer {
    margin-top: 15px;
    width: 100%;
    text-align: center;
    .scan-switch-btn {
      color: vars.$primary-color;
      font-size: 14px;
    }
  }
}
</style>
